package com.zx.core.wrapper;

import com.zx.core.enums.WrapperErrEum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * <p>
 * description: 响应包装类 <br>
 * </p>
 *
 * @author zhou  xun
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseWrapper implements Serializable {
    /**
     * 错误码
     */
    private Integer code = WrapperErrEum.SUCCESS.getCode();
    /**
     * 消息
     */
    private String msg = WrapperErrEum.SUCCESS.getMsg();

    /**
     * 设置错误消息
     *
     * @param msg 消息
     */
    public void fail(String msg) {
        this.msg = msg;
        this.code = WrapperErrEum.FAIL.getCode();
    }

    /**
     * 设置未知消息
     *
     * @param msg 未知错误的消息
     */
    public void unknown(String msg) {
        this.msg = msg;
        this.code = WrapperErrEum.UNKNOWN_ERROR.getCode();
    }

    /**
     * 判断是否成功
     *
     * @return boolean
     */
    public boolean verifySuccess() {
        return WrapperErrEum.SUCCESS.getCode().equals(code);
    }

    /**
     * 判断是否失败
     *
     * @return boolean
     */
    public boolean verifyFail() {
        return WrapperErrEum.FAIL.getCode().equals(code);
    }

    /**
     * 判断是否未知错误
     *
     * @return boolean
     */
    public boolean verifyUnknown() {
        return WrapperErrEum.UNKNOWN_ERROR.getCode().equals(code);
    }
}